package com.cyandpos.pad.activity;

import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import com.cyandpos.pad.R;
import com.cyandpos.pad.offline.adapter.DbAdapter;
import com.cyandpos.pad.offline.offlinedb.OfflineManager;
import com.cyandpos.pad.utils.ToastUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;

public class OfflineDbManagerActivity extends BaseActivity implements View.OnClickListener {
    @BindView(R.id.tv_dialog_title_name)
    TextView tv_dialog_title_name;
    @BindView(R.id.db_listview)
    ListView db_listview;
    @BindView(R.id.bt_delete)
    Button bt_delete;
    DbAdapter dbAdapter;
    List<HashMap<String,Object>> list;
    @Override
    protected void initData() {
        tv_dialog_title_name.setText("数据库查询");
        bt_delete.setOnClickListener(this);
        tv_dialog_title_name.setOnClickListener(this);
        list= OfflineManager.getDbData();
        if(list!=null&&list.size()>0) {
            dbAdapter=new DbAdapter(list,this);
            db_listview.setAdapter(dbAdapter);
        }
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_offline;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tv_dialog_title_name:
                finish();
                break;
            case R.id.bt_delete:
                OfflineManager.updateOfflineDbName();
                ToastUtils.show("本地数据库删除成功!");
                list= new ArrayList<>();
                dbAdapter=new DbAdapter(list,this);
                db_listview.setAdapter(dbAdapter);

                break;
        }
    }
}
